<script type="text/javascript">
	$(function(){
		var id = $.randomBetween(100, 1000);
		$("#icaptcha").attr("src","<?=base_url()?>authorize/captcha/"+id+"");
		$("#icaptcha").click(function(){
			id = $.randomBetween(100, 1000);
            $("#icaptcha").attr("src","<?=base_url()?>authorize/captcha/"+id+"");
        });
		
		$("#reload").click(function(){ 
			id = $.randomBetween(100, 1000);
			var img = "<?=base_url()?>authorize/captcha/"+id;
            $("#icaptcha").attr("src",img);
        });
		 $("#error").val("");
		$("#btn_login").click(function(){			
			login();
		});
		$(window).keypress(function(e) { 
            if (e.which == 13) {
				 login();
			}
		});
		function login(){
			 $("#error").val("");			 
			 var url = "<?=base_url()?>authorize/login";
			 var username = $("#username").val();
			 var password = $("#password").val();
			 var txtcaptcha = $("#txtcaptcha").val();
			 if(username=="") {
				 $("#error").html("Chưa nhập tài khoản");
			 } else if(password=="") {
				 $("#error").html("Chưa nhập mật khẩu");
			 } else if(txtcaptcha=="") {
				 $("#error").html("Chưa nhập chuỗi xác thực");
			 } else {
				 $("#loading").show();
				 $.ajax({
					url:url,
					async: false,
					type: 'POST',
					data:{login:username,password:password,captcha:txtcaptcha},
					success:function(datas) {
						if(datas=="00" || datas=="01" || datas=="0") {
							id = $.randomBetween(100, 1000);
							$("#icaptcha").attr("src","<?=base_url()?>authorize/captcha/"+id+"");
							$("#password,#txtcaptcha").val('');
							$("#error").html(datas);
							$("#loading").hide();
							if(datas=="00") {
								$("#error").html("Đăng nhập không thành công");
							} else if(datas=="01") {
								$("#error").html("Chưa nhập chuỗi xác thực");
							}
							else if(datas=="0") {
								$("#error").html("Tài khoản hoặc mật khẩu không đúng");
							}
						}
						else if(datas=="1"){
							window.location = '<?=base_url()?>klgb.html';
						}	
					}
				});
			 }
		}
	});
</script>
<div class="w100pt">
      <div class="w450 mtop30 h20" id="error"></div>
</div>
<div class="login bd">
    <div class="w100pt fleft f20 MavenProOTF fcolor ">Đăng nhập</div>
    <div class="w100pt fleft mtop20">
        <div class="iconemail"><img class="imgmail" width="24" height="20" src="<?=url_tmpl()?>img/email.png" /></div>
        <div class="fleft"><input id="username"  style="height:30px !important" placeholder="Tài khoản" class="txt_login"/></div>
        <div class="clear"></div>
    </div>
    <div class="w100pt fleft mtop20">
        <div class="iconemail"><img class="imgkey" width="22" height="22" src="<?=url_tmpl()?>img/key.png" /></div>
        <div class="fleft"><input id="password" value="" style="height:30px !important" type="password" placeholder="Mật khẩu" class="txt_login" /></div>
        <div class="clear"></div>
    </div>
    <div class="w100pt fleft mtop20">
    		<div class="fleft">
           		<input id="txtcaptcha" style="height:30px !important" type="text" placeholder="Mã xác nhận" class="txt_login w200" />
           </div>
    	   <div class="fleft mleft10">
           		<img height="30"  title="Click chuột để tạo mã xác nhận khác"  src="<?=base_url()?>authorize/captcha/543534<?=url_suffix()?>" id="icaptcha" class="icaptchas">
           </div>
    	   <div class="fleft">
           	<img id="reload"  title="Click chuột để tạo mã xác nhận khác" style="cursor:pointer; margin-left:15px; margin-top:5px;" align="absmiddle" src="<?=url_tmpl();?>img/reload.png" />
           </div>
           
    </div>
    <div class="w100pt fleft mtop20">
        <div class="fleft mtop10"><input class="checkbox" type="checkbox" /></div>
        <div class="fleft mleft10 mtop10">Nhớ mật khẩu</div>
		<div class="fleft mleft150 mtop10"><span style="display:none" id="loading"><img src="<?=url_tmpl()?>img/loading.gif" /></span></div>
        <div id="btn_login" class="btn_login">Login</div>
        <div class="clear"></div>
    </div>
    <div class="clear"></div>
</div>